

const navbar = document.querySelector('.navbar')

function isBackground() {
    //为了保证兼容性，这里取两个值，哪个有值取哪一个
    //scrollTop就是触发滚轮事件时滚轮的高度
    var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
    if(scrollTop > 100){
        navbar.classList.add('bacground')
    }else{
        navbar.classList.remove('bacground')
    }
}

window.onscroll = isBackground

window.addEventListener("load", function (){
    isBackground()
})

